package com.example.demo18.demos.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

@Controller
public class HomeworkPractiseController {

    @GetMapping("/hello")
    @ResponseBody
    public String hello() {
        return "hello!world";
    }
    
    @GetMapping("/random")
    @ResponseBody
    public String random() {
        Random random = new Random();
        int randomNumber = random.nextInt(1000) + 1;
        return ""+ randomNumber;
    }
    @GetMapping("/square/{number}")
    @ResponseBody
    public int calculateSquare(@PathVariable int number) {
        int square = number * number;
        return square;
    }
    @RequestMapping({"/", "/toIndex"})
    public String toIndex(Model model) {
        model.addAttribute("message", "Hello,how are you doing?");
        return "index";
    }


}
